#include <linux/module.h>
#include <linux/of.h>
#include <linux/gpio/consumer.h>

static int my_led_probe(struct platform_device *pdev)
{
    struct device *dev = &pdev->dev;
    struct gpio_desc *led_gpio;
    int ret;

    led_gpio = devm_gpiod_get(dev, NULL, GPIOD_OUT_LOW);
    if (IS_ERR(led_gpio)) {
        dev_err(dev, "Failed to get LED GPIO\n");
        return PTR_ERR(led_gpio);
    }

    // 在这里执行LED控制操作，例如点亮LED
    gpiod_set_value(led_gpio, 1);

    return 0;
}

static int my_led_remove(struct platform_device *pdev)
{
    struct device *dev = &pdev->dev;

    // 在这里执行LED释放操作，例如熄灭LED
    struct gpio_desc *led_gpio = dev_get_drvdata(dev);
    gpiod_set_value(led_gpio, 0);

    return 0;
}

static const struct of_device_id my_led_dt_ids[] = {
    { .compatible = "my-led" },
    { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, my_led_dt_ids);

static struct platform_driver my_led_platform_driver = {
    .probe = my_led_probe,
    .remove = my_led_remove,
    .driver = {
        .name = "my-led",
        .of_match_table = my_led_dt_ids,
        .owner = THIS_MODULE,
    },
};

static int __init my_led_init(void)
{
    return platform_driver_register(&my_led_platform_driver);
}

static void __exit my_led_exit(void)
{
    platform_driver_unregister(&my_led_platform_driver);
}

module_init(my_led_init);
module_exit(my_led_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("My LED Driver");

